package com.nariano.server.domain.entities;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

@Entity
@Table(name="nariano_user")
public class User implements Serializable {
    
    public User() {}
    
    public User(String userName, String email, String passwordHashed) {

        this.email = email;
        this.passwordHashed = passwordHashed;
        this.userName = userName;
    }
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name="user_id")
    private Integer id;
    
    @Column(name="user_name")
    private String userName;
    
    @Column(name="email")
    private String email;
    
    @Column(name="password_hashed")
    private String passwordHashed;

    @Column(name="points")
    private int points;
    
    @Column(name="resources")
    private int resources;
    
    @Column(name="enemy_user_id")
    Integer enemyUserId;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPasswordHashed() {
        return passwordHashed;
    }

    public void setPasswordHashed(String passwordHashed) {
        this.passwordHashed = passwordHashed;
    }
    
    public int getPoints() {
		return points;
	}

	public void setPoints(int points) {
		this.points = points;
	}

	public void addPoints(int points) {
		this.points += points;
	}
	
    public int getResources() {
		return resources;
	}

	public void setResources(int resources) {
		this.resources = resources;
	}
	
	public void addResources(int resoures) {
		this.resources += resoures;
	}

	public Integer getEnemyUserId() {
		return enemyUserId;
	}

	public void setEnemyUserId(Integer enemyUserId) {
		this.enemyUserId = enemyUserId;
	}

	@Override
    public String toString() {
    	return String.format("User[id=%d, userName=%s]", id, userName); 
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((id == null) ? 0 : id.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        User other = (User) obj;
        if (id == null) {
            if (other.id != null)
                return false;
        } else if (!id.equals(other.id))
            return false;
        return true;
    }

    
}
